package com.androidx.p013lv.base.utils;

import com.androidx.p013lv.base.BaseApp;
import com.androidx.p013lv.base.bean.NovelHistory;
import com.androidx.p013lv.base.p014db.NovelHistoryDao;
import java.util.List;
import org.greenrobot.greendao.query.WhereCondition;
import p023io.reactivex.BackpressureStrategy;
import p023io.reactivex.Completable;
import p023io.reactivex.CompletableEmitter;
import p023io.reactivex.CompletableOnSubscribe;
import p023io.reactivex.Flowable;
import p023io.reactivex.FlowableEmitter;
import p023io.reactivex.FlowableOnSubscribe;

/* renamed from: com.androidx.lv.base.utils.NovelHistoryUtils */
public class NovelHistoryUtils {
    static NovelHistoryUtils videoHistoryUtils;

    public static NovelHistoryUtils getInstance() {
        if (videoHistoryUtils == null) {
            videoHistoryUtils = new NovelHistoryUtils();
        }
        return videoHistoryUtils;
    }

    public NovelHistoryDao getDao() {
        return BaseApp.getDaoSession().getNovelHistoryDao();
    }

    public Completable insert(final NovelHistory novelHistory) {
        return Completable.create(new CompletableOnSubscribe() {
            /* class com.androidx.p013lv.base.utils.NovelHistoryUtils.C10541 */

            @Override // p023io.reactivex.CompletableOnSubscribe
            public void subscribe(CompletableEmitter completableEmitter) throws Exception {
                NovelHistoryDao dao = NovelHistoryUtils.this.getDao();
                List list = dao.queryBuilder().where(NovelHistoryDao.Properties.FictionId.mo36808eq(Integer.valueOf(novelHistory.getFictionId())), new WhereCondition[0]).build().list();
                NovelHistory novelHistory = (list == null || list.size() <= 0) ? null : (NovelHistory) list.get(0);
                if (novelHistory != null) {
                    dao.delete(novelHistory);
                }
                dao.insert(novelHistory);
                completableEmitter.onComplete();
            }
        });
    }

    public Completable delete(final List<NovelHistory> list) {
        return Completable.create(new CompletableOnSubscribe() {
            /* class com.androidx.p013lv.base.utils.NovelHistoryUtils.C10552 */

            @Override // p023io.reactivex.CompletableOnSubscribe
            public void subscribe(CompletableEmitter completableEmitter) throws Exception {
                NovelHistoryUtils.this.getDao().deleteInTx(list);
                completableEmitter.onComplete();
            }
        });
    }

    public Completable delete(final NovelHistory novelHistory) {
        return Completable.create(new CompletableOnSubscribe() {
            /* class com.androidx.p013lv.base.utils.NovelHistoryUtils.C10563 */

            @Override // p023io.reactivex.CompletableOnSubscribe
            public void subscribe(CompletableEmitter completableEmitter) throws Exception {
                NovelHistoryUtils.this.getDao().delete(novelHistory);
                completableEmitter.onComplete();
            }
        });
    }

    public Flowable<List<NovelHistory>> select(final int i) {
        return Flowable.create(new FlowableOnSubscribe<List<NovelHistory>>() {
            /* class com.androidx.p013lv.base.utils.NovelHistoryUtils.C10574 */

            @Override // p023io.reactivex.FlowableOnSubscribe
            public void subscribe(FlowableEmitter<List<NovelHistory>> flowableEmitter) throws Exception {
                flowableEmitter.onNext(NovelHistoryUtils.this.getDao().queryBuilder().orderDesc(NovelHistoryDao.Properties.f178Id).offset(i * 30).limit(30).build().list());
            }
        }, BackpressureStrategy.ERROR);
    }
}
